package cn.xydpeng.springframework.core;

import cn.xydpeng.springframework.lang.Nullable;
import cn.xydpeng.springframework.util.Assert;

import java.io.Serializable;
import java.lang.reflect.Type;

/**
 * @author xydpeng
 * @version v1.0
 * @date: 2022/10/21
 * @description: 封装Java｛@link Java.lang.reflect.Type｝，提供对
 * ｛@link#getSuperType（）超类型｝、｛@link#getInterfaces（）接口｝和
 * ｛@link#getGeneric（int…）泛型参数｝
 */
//TODO 此工具类逻辑比较复杂，暂未实现
public class ResolvableType implements Serializable {
    /**
     * The underlying Java type being managed.
     */
    private final Type type;
    @Nullable
    private Class<?> resolved;

    private ResolvableType(@Nullable Class<?> clazz) {
        this.resolved = (clazz != null ? clazz : Object.class);
        this.type = this.resolved;
    }

    public static ResolvableType forClass(@Nullable Class<?> clazz) {
        return new ResolvableType(clazz);
    }

    public static ResolvableType forInstance(@Nullable Object instance) {
        Assert.notNull(instance,"ResolvableType forInstance not null");
        return forClass(instance.getClass());
    }

    public Class<?> getResolved() {
        return resolved;
    }
}
